<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>景旭商城-我的账号</title>
<%@ include file="/page/pc/include.jsp"%>

</head>
<body>
	<div class="wrap">
		<jsp:include page="../_my_header.jsp" />
		<div class="site_wrap18">
			<div class="site_wrap18_con">
				<div class="main">
					<jsp:include page="../_my_left.jsp" />
					<div class="rightitem">
						<div class="dd_part">
							<div class="hd">
								<h3>新增账户</h3>
							</div>
							<div class="grxx_con" style="background: #fff">
								<div class="grxx_info3">
									<div>
										<dl>
											<dt>
												<strong>账户类型：</strong>
												<div class="txt1">
													<ul>
														<li>
															<input type="radio" name="accountType" value="2" checked="checked" />
															<label class="checked" title="alipay">
																<i></i>
																<span>支付宝</span>
																</label>
															</li>
														<li>
															<input name="accountType" type="radio" value="1" />
															<label title="bank">
																<i></i>
																<span>银行卡</span>
															</label>
														</li>
													</ul>
												</div>
											</dt>
										</dl>
									</div>
									<div class="myinfo1" id="alipay_info">
										<dl>
											<dt>
												<strong>支付宝账号：</strong>
												<div class="txt1">
													<input type="text" id="alipayAccount" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>账户姓名：</strong>
												<div class="txt1">
													<input type="text" id="alipayAccountName" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>备注：</strong>
												<div class="txt1">
													<div class="textarea1">
														<textarea id="alipayRemark"></textarea>
													</div>
												</div>
											</dt>
										</dl>
									</div>
									<div class="myinfo1" id="bank_info" style="display: none">
										<dl>
											<dt>
												<strong>开户姓名：</strong>
												<div class="txt1">
													<input type="text" id="accountName" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>银行卡号：</strong>
												<div class="txt1">
													<input type="text" id="accountCode" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>开户银行：</strong>
												<div class="txt1">
													<input type="text" id="bankName" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>所属支行：</strong>
												<div class="txt1">
													<input type="text" id="subBankName" class="inputstyle1" />
												</div>
											</dt>
											<dt>
												<strong>备注：</strong>
												<div class="txt1">
													<div class="textarea1">
														<textarea id="intro"></textarea>
													</div>
												</div>
											</dt>
										</dl>
									</div>
									<dl>
										<dt>
											<strong>&nbsp;</strong>
											<div class="txt1">
												<input type="button" class="inputbtn1" value="保存"
													style="margin-top: 0" onclick="javascript: doSaveAccount();" />
											</div>
										</dt>
									</dl>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div>
		<!---网站底部开始-->
		<jsp:include page="../../footer.jsp?showQaFlag=0" />
		<!---网站底部结束-->
	</div>
<script type="text/javascript">
/**
 * 保存账号
 */
function doSaveAccount() {
	var accountType = $('input[name="accountType"][checked="checked"]').val();
	console.log(accountType);
	// 开户行名称
	var bankName = null;
	// 所属支行
	var subBankName = null;
	// 账户姓名
	var accountName = null;
	// 账号
	var accountCode = null;
	// 支付宝
	var alipayAccount = null;
	// 备注
	var intro = null;
	if (accountType == 1) {
		bankName = $("#bankName").val();
		subBankName = $("#subBankName").val();
		accountName = $("#accountName").val();
		accountCode = $("#accountCode").val();
		alipayAccount = $("#alipayAccount").val();
		intro = $("#intro").val();
		if(!accountName) {
			layer.msg('请输入开户姓名');
			return;
		}
		if(!accountCode) {
			layer.msg('请输入银行卡号');
			return;
		}
		if(!bankName) {
			layer.msg('请输入开户银行');
			return;
		}
	} else if (accountType == 2) {
		// 支付宝
		alipayAccount = $("#alipayAccount").val();
		accountName = $("#alipayAccountName").val();
		intro = $("#alipayRemark").val();
		if(!accountName) {
			layer.msg('请输入开户姓名');
			return;
		}
		if(!alipayAccount) {
			layer.msg('请输入支付宝帐号');
			return;
		}
	} else {
		layer.msg('未知的账户类型');
		return;
	}
	
	$.ajax({
		type : "post",
		url : rootPath + '/pc/my/account/doAddAccount',
		data : {
			accountType : accountType,
			bankName : bankName,
			subBankName : subBankName,
			accountName : accountName,
			accountCode : accountCode,
			alipayAccount : alipayAccount,
			intro : intro 
		},
		async : false,
		datatype : "json",
		success : function(json) {
			layer.msg(json.resultMsg);
			if (json.resultCode == '1') {
				window.location.href = rootPath + "/pc/my/account/myAccount";
			}
		},
		error : function() {
			layer.msg('保存帐号失败', {
				time : 1000
			});
		}
	});
	
	
	
}

$(function() {
	$('.grxx_info3 dl dt .txt1 ul li label').click(function() {
		var x = $(this).attr('title');
		if (x == 'alipay') {
			$('#bank_info').hide();
			$('#alipay_info').show();
		} else {
			$('#bank_info').show();
			$('#alipay_info').hide();
		}
		$("input[name='accountType']").removeAttr("checked");
		if ($(this).hasClass('checked')) {
			$(this).addClass('checked');
			$(this).parent().find('input').attr('checked', 'true');
		} else {
			//$(this).parent().find('input').attr('checked', 'checked');
			//$(this).parent().siblings().find('input').attr('checked', '');
			$(this).addClass('checked');
			$(this).parent().siblings().find('label').removeClass('checked');
			$(this).parent().find('input').attr('checked', 'true');
		}
	});

});
</script>
</body>
</html>